<?php
//王晓梦
use think\facade\Route;
use think\facade\Request;

$version = Request::header('version', 'v1');#第一版接口版本
$versions = Request::header('version', 'v2');#第二版接口版本

//第一版
Route::group('', function () use ($version) {
    // 登录
    Route::group('site', function () use ($version) {
        Route::post('login', "backend/{$version}.Site/login");
    });

    // 后台用户管理
    Route::group('backendMember', function () use ($version) {
        Route::get('read', "backend/{$version}.BackendMember/read");
        Route::get('create', "backend/{$version}.BackendMember/create");
        Route::post('save', "backend/{$version}.BackendMember/save");
        Route::post('update', "backend/{$version}.BackendMember/update");
        Route::get('edit', "backend/{$version}.BackendMember/edit");
        Route::delete('delete', "backend/{$version}.BackendMember/delete");
        Route::get(':id', "backend/{$version}.BackendMember/index");
        //  获取后台角色信息
        Route::get('get-role', "backend/{$version}.BackendMember/getrole");
        Route::get('member-info', "backend/{$version}.BackendMember/memberInfo");
        Route::get('login-out', "backend/{$version}.BackendMember/loginOut");
        //  清除缓存
        Route::get('clear-cache', "backend/{$version}.BackendMember/clearcache");
    })->middleware('checkLogin');

    // 会员管理
    Route::group('member', function () use ($version) {
        Route::get('index', "backend/{$version}.Member/index");
        Route::post('create', "backend/{$version}.Member/create");
        Route::put('update', "backend/{$version}.Member/update");
        Route::delete('delete', "backend/{$version}.Member/delete");
    })->middleware('checkLogin');

    //节点管理
    Route::group('permission', function () use ($version) {
        Route::get('index', "backend/{$version}.BackendPermission/index");
        Route::get('create', "backend/{$version}.BackendPermission/create");
        Route::post('save', "backend/{$version}.BackendPermission/save");
        Route::post('update', "backend/{$version}.BackendPermission/update");
        Route::get('edit', "backend/{$version}.BackendPermission/edit");
        Route::delete('delete', "backend/{$version}.BackendPermission/delete");
    })->middleware('checkLogin');

    //角色管理
    Route::group('role', function () use ($version) {
        Route::get('index', "backend/{$version}.BackendRole/index");
        Route::post('save', "backend/{$version}.BackendRole/save");
        Route::post('update', "backend/{$version}.BackendRole/update");
        Route::get('edit', "backend/{$version}.BackendRole/edit");
        Route::delete('delete', "backend/{$version}.BackendRole/delete");
    })->middleware('checkLogin');

    //角色权限
    Route::group('rolePermission', function () use ($version) {
        Route::get('create', "backend/{$version}.BackendRolePermission/create");
        Route::get('index', "backend/{$version}.BackendRolePermission/index");
        Route::post('save', "backend/{$version}.BackendRolePermission/save");
        Route::post('update', "backend/{$version}.BackendRolePermission/update");
        Route::get('edit', "backend/{$version}.BackendRolePermission/edit");
        Route::delete('delete', "backend/{$version}.BackendRolePermission/delete");
    })->middleware('checkLogin');

    //联系我们
    Route::group('contact', function () use ($version) {
        Route::get('index', "backend/{$version}.contact/index");
        Route::get('edit', "backend/{$version}.contact/edit");
        Route::post('update', "backend/{$version}.contact/update");
    })->middleware('checkLogin');

    //网站基础设置
    Route::group('baseSite', function () use ($version) {
        Route::get('index', "backend/{$version}.baseSite/index");
        Route::get('edit', "backend/{$version}.baseSite/edit");
        Route::post('update', "backend/{$version}.baseSite/update");
    })->middleware('checkLogin');

    //热门话题
    Route::group('hot', function () use ($version) {
        Route::get('index', "backend/{$version}.hot/index");
        Route::post('save', "backend/{$version}.hot/save");
        Route::post('update', "backend/{$version}.hot/update");
        Route::get('edit', "backend/{$version}.hot/edit");
        Route::delete('delete', "backend/{$version}.hot/delete");
    })->middleware('checkLogin');

    //代码知识
    Route::group('article', function () use ($version) {
        Route::get('index', "backend/{$version}.article/index");
        Route::get('create', "backend/{$version}.article/create");
        Route::post('save', "backend/{$version}.article/save");
        Route::post('update', "backend/{$version}.article/update");
        Route::get('edit', "backend/{$version}.article/edit");
        Route::delete('delete', "backend/{$version}.article/delete");
    })->middleware('checkLogin');

    //轮播管理
    Route::group('banner', function () use ($version) {
        Route::get('index', "backend/{$version}.banner/index");
        Route::post('save', "backend/{$version}.banner/save");
        Route::post('update', "backend/{$version}.banner/update");
        Route::get('edit', "backend/{$version}.banner/edit");
        Route::delete('delete', "backend/{$version}.banner/delete");
    })->middleware('checkLogin');

    //实例、素材管理
    Route::group('cases', function () use ($version) {
        Route::get('create', "backend/{$version}.cases/create");
        Route::get('index', "backend/{$version}.cases/index");
        Route::post('save', "backend/{$version}.cases/save");
        Route::post('update', "backend/{$version}.cases/update");
        Route::get('edit', "backend/{$version}.cases/edit");
        Route::delete('delete', "backend/{$version}.cases/delete");
    })->middleware('checkLogin');

    //用户搜索记录管理
    Route::group('search', function () use ($version) {
        Route::get('index', "backend/{$version}.search/index");
        Route::delete('delete', "backend/{$version}.search/delete");
    })->middleware('checkLogin');

    //用户评论管理
    Route::group('comment', function () use ($version) {
        Route::get('index', "backend/{$version}.comment/index");
        Route::delete('delete', "backend/{$version}.comment/delete");
    })->middleware('checkLogin');

    //上传
    Route::group('upload', function () use ($version) {
        Route::post('upload', "backend/{$version}.cases/upload");
    });

    //合作伙伴管理
    Route::group('friend', function () use ($version) {
        Route::get('index', "backend/{$version}.friend/index");
        Route::post('save', "backend/{$version}.friend/save");
        Route::post('update', "backend/{$version}.friend/update");
        Route::get('edit', "backend/{$version}.friend/edit");
        Route::delete('delete', "backend/{$version}.friend/delete");
    })->middleware('checkLogin');

    //合作项目
    Route::group('cooperate', function () use ($version) {
        Route::get('index', "backend/{$version}.cooperate/index");
        Route::post('save', "backend/{$version}.cooperate/save");
        Route::post('update', "backend/{$version}.cooperate/update");
        Route::get('edit', "backend/{$version}.cooperate/edit");
        Route::delete('delete', "backend/{$version}.cooperate/delete");
    })->middleware('checkLogin');

})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST,DELETE,PUT',
    'Access-Control-Allow-Headers' => 'content-type,token,version',
    'Access-Control-Allow-Credentials' => 'true'
]);


//第二版
Route::group('v2', function () use ($versions) {
    //上传
    Route::group('upload', function () use ($versions) {
        Route::post('upload', "backend/{$versions}.Upload/upload");
    });

    //联系我们
    Route::group('website', function () use ($versions) {
        Route::get('index', "backend/{$versions}.Website/index");
        Route::get('edit', "backend/{$versions}.Website/edit");
        Route::post('update', "backend/{$versions}.Website/update");
    })->middleware('checkLogin');

    //导航
    Route::group('nav', function () use ($versions) {
        Route::get('index', "backend/{$versions}.Nav/index");
        Route::get('edit', "backend/{$versions}.Nav/edit");
        Route::post('update', "backend/{$versions}.Nav/update");
    })->middleware('checkLogin');

    //banner
    Route::group('banner', function () use ($versions) {
        Route::get('index', "backend/{$versions}.banner/index");
        Route::post('save', "backend/{$versions}.banner/save");
        Route::get('edit', "backend/{$versions}.banner/edit");
        Route::post('update', "backend/{$versions}.banner/update");
        Route::delete('delete', "backend/{$versions}.banner/delete");
    })->middleware('checkLogin');

    //分类管理
    Route::group('cate', function () use ($versions) {
        Route::get('index', "backend/{$versions}.cate/index");//列表
        Route::get('create', "backend/{$versions}.cate/create");//获取父级
        Route::post('save', "backend/{$versions}.cate/save");//添加
        Route::get('edit', "backend/{$versions}.cate/edit");//查看编辑时的数据
        Route::post('update', "backend/{$versions}.cate/update");//修改
        Route::delete('delete', "backend/{$versions}.cate/delete");//删除
    })->middleware('checkLogin');

    //实例管理
    Route::group('example', function () use ($versions) {
        Route::get('indexcate', "backend/{$versions}.example/indexcate");//显示分类列表
        Route::get('create', "backend/{$versions}.example/create");//获取分类
        Route::post('savecate', "backend/{$versions}.example/savecate");//添加分类
        Route::post('editcate', "backend/{$versions}.example/editcate");//修改分类
        Route::delete('deletecate', "backend/{$versions}.example/deletecate");//删除分类
        Route::get('index', "backend/{$versions}.example/index");
        Route::post('save', "backend/{$versions}.example/save");//添加
        Route::get('edit', "backend/{$versions}.example/edit");
        Route::post('update', "backend/{$versions}.example/update");
        Route::delete('delete', "backend/{$versions}.example/delete");
    })->middleware('checkLogin');

    //素材库管理
    Route::group('picture', function () use ($versions) {
        Route::get('index', "backend/{$versions}.Picture/index");
        Route::post('save', "backend/{$versions}.Picture/save");//添加
        Route::get('edit', "backend/{$versions}.Picture/edit");
        Route::post('update', "backend/{$versions}.Picture/update");
        Route::delete('delete', "backend/{$versions}.Picture/delete");
        Route::get('indexcate', "backend/{$versions}.Picture/indexcate");//获取列表
        Route::get('createcate', "backend/{$versions}.Picture/createcate");//获取父级
        Route::post('savecate', "backend/{$versions}.Picture/savecate");//添加分类
        Route::post('editcate', "backend/{$versions}.Picture/editcate");//修改分类
        Route::delete('deletecate', "backend/{$versions}.Picture/deletecate");//删除分类
    })->middleware('checkLogin');

    //代码知识
    Route::group('technology', function () use ($versions) {
        Route::get('index', "backend/{$versions}.technology/index");
        Route::post('save', "backend/{$versions}.technology/save");//添加
        Route::get('edit', "backend/{$versions}.technology/edit");
        Route::post('update', "backend/{$versions}.technology/update");
        Route::delete('delete', "backend/{$versions}.technology/delete");
        Route::get('indexcate', "backend/{$versions}.technology/indexcate");//获取列表
        Route::get('createcate', "backend/{$versions}.technology/createcate");//获取父级
        Route::post('savecate', "backend/{$versions}.technology/savecate");//添加分类
        Route::post('editcate', "backend/{$versions}.technology/editcate");//修改分类
        Route::delete('deletecate', "backend/{$versions}.technology/deletecate");//删除分类
    })->middleware('checkLogin');

    //问答管理
    Route::group('question', function () use ($versions) {
        Route::get('index', "backend/{$versions}.Question/index");
        Route::post('save', "backend/{$versions}.Question/save");//添加
        Route::get('edit', "backend/{$versions}.Question/edit");
        Route::post('update', "backend/{$versions}.Question/update");
        Route::delete('delete', "backend/{$versions}.Question/delete");
        Route::get('indexcate', "backend/{$versions}.Question/indexcate");//获取列表
        Route::get('createcate', "backend/{$versions}.Question/createcate");//获取父级
        Route::post('savecate', "backend/{$versions}.Question/savecate");//添加分类
        Route::post('editcate', "backend/{$versions}.Question/editcate");//修改分类
        Route::delete('deletecate', "backend/{$versions}.Question/deletecate");//删除分类
    })->middleware('checkLogin');

    //文章管理
    Route::group('article', function () use ($versions) {
        Route::get('index', "backend/{$versions}.Article/index");
        Route::post('save', "backend/{$versions}.Article/save");//添加
        Route::get('edit', "backend/{$versions}.Article/edit");
        Route::post('update', "backend/{$versions}.Article/update");
        Route::delete('delete', "backend/{$versions}.Article/delete");
        Route::get('indexcate', "backend/{$versions}.Article/indexcate");//获取列表
        Route::get('createcate', "backend/{$versions}.Article/createcate");//获取父级
        Route::post('savecate', "backend/{$versions}.Article/savecate");//添加分类
        Route::post('editcate', "backend/{$versions}.Article/editcate");//修改分类
        Route::delete('deletecate', "backend/{$versions}.Article/deletecate");//删除分类
    })->middleware('checkLogin');

    //文章点赞记录管理
    Route::group('articlezan', function () use ($versions) {
        Route::get('index', "backend/{$versions}.ArticleZan/index");
    })->middleware('checkLogin');

    //实例点赞记录管理
    Route::group('examplezan', function () use ($versions) {
        Route::get('index', "backend/{$versions}.ExampleZan/index");
    })->middleware('checkLogin');

    //问答点赞记录管理
    Route::group('questionzan', function () use ($versions) {
        Route::get('index', "backend/{$versions}.QuestionZan/index");
    })->middleware('checkLogin');

    //技术社区点赞记录管理
    Route::group('technologyzan', function () use ($versions) {
        Route::get('index', "backend/{$versions}.TechnologyZan/index");
    })->middleware('checkLogin');

})->allowCrossDomain([
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Allow-Methods' => 'GET,POST,DELETE,PUT',
    'Access-Control-Allow-Headers' => 'content-type,token,version',
    'Access-Control-Allow-Credentials' => 'true'
]);
